home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / scsiHBA.h < prev    next >
C/C++ Source or Header  |  1991-07-27  |  7KB  |  191 lines

  1. /*
  2.  * scsiHBA.h --
  3.  *
  4.  *    Declarations of the data structures and routines defining the
  5.  *    interface between the scsiDevice code and SCSI HBAs.  
  6.  *
  7.  *     An SCSI HBA must export a single routine that allows 
  8.  *    SCSI devices to be attached. The attach routine should return
  9.  *    a ScsiDevice structure for the device. All further activity 
  10.  *    to the device is directed though this SssiDevice structure.
  11.  *
  12.  * Copyright 1989 Regents of the University of California
  13.  * Permission to use, copy, modify, and distribute this
  14.  * software and its documentation for any purpose and without
  15.  * fee is hereby granted, provided that the above copyright
  16.  * notice appear in all copies.  The University of California
  17.  * makes no representations about the suitability of this
  18.  * software for any purpose.  It is provided "as is" without
  19.  * express or implied warranty.
  20.  *
  21.  * $Header: /sprite/src/kernel/dev/RCS/scsiHBA.h,v 9.2 91/07/27 13:56:25 mottsmth Exp $ SPRITE (Berkeley)
  22.  */
  23.  
  24. #ifndef _SCSIHBA
  25. #define _SCSIHBA
  26.  
  27. /*
  28.  * Get the ScsiCmd and ScsiDevice typedefs from scsiDevice.h
  29.  */
  30. #include "scsiDevice.h"
  31.  
  32. /*
  33.  * The following fields of the ScsiDevice must be initialized by 
  34.  * the HBA AttachDeviceProc
  35.  *
  36.  * Field: devQueue 
  37.  *    Should be a device queue return by Dev_QueueCreate.
  38.  *
  39.  * Field: locationName
  40.  *    Should be an ASCII character string specifing the SCSI device 
  41.  *    location on this HBA. This is used in error message and should point
  42.  *    the system admin at the device.
  43.  *
  44.  * Field: LUN
  45.  *    The logical unit number of the device.
  46.  * Field: maxTransferSize
  47.  *    The maximum transfer size supported by the HBA.
  48.  * Field: referenceCount
  49.  *    To zero when the device is first attached.
  50.  * Field: releaseProc 
  51.  *    The release procedure for the device. Should be declared.
  52.  *
  53.  *     ReturnStatus releaseProc(scsiDevicePtr)
  54.  *       ScsiDevice    *scsiDevicePtr;   -- Handle for the device to release.
  55.  *
  56.  */
  57.  
  58. /*
  59.  * The following definitions should all the SCSI HBA needs know about
  60.  * the format of SCSI command blocks.  
  61.  */
  62.  
  63. /*
  64.  * SCSI status byte 
  65.  * The most significant 2 bits and least significant bit are reserved.
  66.  */
  67.  
  68. #define    SCSI_STATUS_MASK           0x3e
  69.  
  70. /* status byte definitions */
  71. #define SCSI_STATUS_GOOD           0x00
  72. #define SCSI_STATUS_CHECK          0x02
  73. #define SCSI_STATUS_COND_MET       0x04
  74. #define SCSI_STATUS_BUSY           0x08
  75. #define SCSI_STATUS_INTER_GOOD     0x10
  76. #define SCSI_STATUS_INTER_COND_MET 0x14
  77. #define SCSI_STATUS_RES_CONFLICT   0x18
  78. #define SCSI_STATUS_CMD_TERMINATED 0x22
  79. #define SCSI_STATUS_QUEUE_FULL     0x28
  80.  
  81. /*
  82.  * SCSI_CHECK_STATUS() - Macro that returns TRUE if a SCSI status byte
  83.  *             requests a REQUEST SENSE.
  84.  */
  85. #define    SCSI_CHECK_STATUS(statusBytes) (((statusBytes)&SCSI_STATUS_CHECK) != 0)
  86. #define    DEV_MAX_SENSE_BYTES    128
  87. #define    DEV_MAX_INQUIRY_SIZE    128
  88.  
  89. /*
  90.  * Definitions of SCSI messages.
  91.  *
  92.  * SCSI_COMMAND_COMPLETE - After a command has completed, successfully
  93.  *    or not, this is returned to the host from the target.
  94.  *
  95.  * The following messages are used with connect/disconnect:
  96.  * SCSI_SAVE_DATA_POINTER - Sent from target to host to request saving
  97.  *    of current DMA address and count.   Indicates a pending dis-connect.
  98.  * SCSI_RESTORE_POINTER - Sent from the target to the host to request
  99.  *    restoring pointers saved before a disconnect
  100.  * SCSI_DISCONNECT - Sent from the target to the host to disconnect.
  101.  * SCSI_ABORT - Sent from the host to the target to abort current request.
  102.  * SCSI_MESSAGE_REJECT -  Indicates reciept, by either host or target, of
  103.  *    an unimplemented message.
  104.  * SCSI_NO_OP - Sent from host to target if it has no real message to send.
  105.  * SCSI_MESSAGE_PARITY_ERROR - Sent from host to target on message parity error
  106.  * SCSI_BUS_RESET - Sent from host to target to reset all current I/O
  107.  *
  108.  * SCSI_IDENTIFY - The low order two bits of this message type indicate
  109.  *    the Logical Unit of the Target which is requesting a reconnect.
  110.  * SCSI_DIS_REC_IDENTIFY - Sent from the host to a target to indicate
  111.  *    is supports connect/dis-connect
  112.  *    
  113.  */
  114. #define SCSI_COMMAND_COMPLETE        0x00
  115. #define SCSI_EXTENDED_MESSAGE        0x01
  116. #define SCSI_SAVE_DATA_POINTER        0x02
  117. #define SCSI_RESTORE_POINTERS        0x03
  118. #define SCSI_DISCONNECT            0x04
  119. #define SCSI_ABORT            0x06
  120. #define SCSI_MESSAGE_REJECT        0x07
  121. #define SCSI_NO_OP            0x08
  122. #define SCSI_MESSAGE_PARITY_ERROR    0x09
  123. #define SCSI_BUS_RESET            0x0C
  124.  
  125. #define SCSI_IDENTIFY            0x80
  126. #define SCSI_DIS_REC_IDENTIFY        0xc0
  127.  
  128. #define SCSI_IDENT_LUN_MASK        0x03
  129.  
  130. /*
  131.  * extended msg codes when msg type = 0x01
  132.  */
  133. #define SCSI_EXTENDED_MSG_MOD_DPTR      0x00
  134. #define SCSI_EXTENDED_MSG_SYNCH         0x01
  135. #define SCSI_EXTENDED_MSG_WIDE          0x03
  136.  
  137. /*
  138.  * devScsiAttachProcs - Table for attach procs indexed by SCSI HBA type.
  139.  * This table is filled in  machine dependent 
  140.  */
  141. extern ScsiDevice *((*devScsiAttachProcs[])());
  142. extern int      devScsiNumHBATypes;
  143.  
  144. /*
  145.  * This section describes the layout of the Fs_Device structure type and
  146.  * unit number fields for SCSI devices.
  147.  *
  148.  * Type: 16 bits
  149.  *   |  Bits 15 to  8   | Bits 7 to 0   |
  150.  *   |  HBA  type       | device type   |
  151.  * Unit:
  152.  *  | Bits 15 to 10 | Bits 9 to 7 | Bits 6 to 4 |  Bits 3 to 0    |
  153.  *  |   HBA Number  |    LUN      |   targetID  | Device specific |
  154.  *
  155.  * This limits a system to at most 256 different types of HBAs. Each HBA has
  156.  * at most 64 instances each supporting a full complement of SCSI devices.
  157.  *
  158.  * Macros for SCSI devices:
  159.  *
  160.  * SCSI_HBA_TYPE()     -      Compute the HBA type from the Fs_Device struct.
  161.  * SCSI_HBA_NUMBER()    -     Compute the HBA number from Fs_Device struct.
  162.  * SCSI_TARGET_ID()    -     Compute the SCSI device's targetID from the
  163.  *                 Fs_Device struct.
  164.  * SCSI_LUN()        -     Compute the SCSI device Logical Unit number
  165.  *                 the Fs_Device struct.
  166.  * SCSI_DEVICE_BITS()    -     Select the device dependent bits from the
  167.  *                 Fs_Device struct.
  168.  * SCSI_MAKE_DEVICE_TYPE() -      Build the type field of the Fs_Device structure
  169.  *                 from the device type and HBA type.
  170.  * SCSI_MAKE_DEVICE_UNIT() -      Build the unit field of the Fs_Device structure
  171.  *                 from its compontends
  172.  */
  173. #define    SCSI_HBA_TYPE(devicePtr)     ((((devicePtr)->type)>>8)&0xff)
  174. #define    SCSI_HBA_NUMBER(devicePtr)     ((((devicePtr)->unit)>>10)&0x3f)
  175. #define    SCSI_TARGET_ID(devicePtr)     ((((devicePtr)->unit)>>4)&0x7)
  176. #define    SCSI_LUN(devicePtr)         ((((devicePtr)->unit)>>7)&0x7)
  177. #define    SCSI_DEVICE_BITS(devicePtr)    (((devicePtr)->unit)&0xf)
  178. #define    SCSI_MAKE_DEVICE_TYPE(type, hbaType, ctrlNum, targetID, LUN, dBits) \
  179.         (((hbaType)<<8)|(type))
  180. #define    SCSI_MAKE_DEVICE_UNIT(type, hbaType, ctrlNum, targetID, LUN, dBits)  \
  181.         (((ctrlNum)<<10)|((LUN)<<7)|((targetID)<<4)|(dBits))
  182. /*
  183.  * Routines.
  184.  */
  185.  
  186. extern void DevScsiSenseCmd _ARGS_((ScsiDevice *scsiDevicePtr, int bufferSize,
  187.     char *buffer, ScsiCmd *scsiCmdPtr));
  188.  
  189. #endif /* _SCSIHBA */
  190.  
  191.